*This script produces the marginal effects plot in Figure 4 for "The Coevolution of Networks of Interstate Support, Interstate Threat and Civil War" 


clear

*cd "[directory information here]"
cd "/Users/kcb38/Library/CloudStorage/Box-Box/Relation creation/JOPreplication/"

*First establish appropriate scale of change, remembering that SAOM models center interacted variales at their means
insheet using "relation_nodal.csv", clear
sum support_mi, detail
sum support_ipcloseness, detail

clear
*Now create graphs using the standard deviations and coefficient values from Model 1 of the SAOM estimation

*SD for support_mi = 0.60
*SD for support_ipcloseness = 0.17
*Coef on alter support_mi for threat = .26
*Coef on support_mi for intra = .18
*Coef on alter support_ipcloseness for threat = -0.61
*Coef on support_ipcloseness for intra = -.79
*Coef on interaction for threat = -.69
*Coef on interaction for intra = -1.97

set obs 11
gen d_support_mi=-.2+(.2*_n)
gen threat_mean_IP=exp(0.60*d_support_mi*0.26)
gen intra_mean_IP=exp(0.60*d_support_mi*0.18)
gen threat_hi_IP=exp((0.60*d_support_mi*0.26)+(2*0.17*0.60*d_support_mi*-0.69) + (2*.17*-0.61))
gen intra_hi_IP=exp((0.60*d_support_mi*0.18)+(2*0.17*0.60*d_support_mi*-1.97) + (2*.17*-0.79)) 
gen threat_lo_IP=exp((0.60*d_support_mi*0.26)+(2*-0.17*0.60*d_support_mi*-0.69) + (2*-.17*-0.61))
gen intra_lo_IP=exp((0.60*d_support_mi*0.18)+(2*-0.17*0.60*d_support_mi*-1.97) + (2*-.17*-0.79))

twoway (line threat_lo_IP d_support_mi, sort lcolor(dknavy) lwidth(thick) lpattern(shortdash)) (line threat_mean_IP d_support_mi, sort lcolor(teal) lwidth(thick) lpattern(solid)) (line threat_hi_IP d_support_mi, sort lcolor(lavender) lwidth(thick) lpattern(dash)), ytitle(Interstate Threat Odds Ratio) ytitle(, margin(medium)) ylabel(.5(.5)3.5) xtitle(Change in j's Support Group Military Spending (sd)) xscale(range(0 2)) xlabel(0(.2)2) legend(on order(1 "Low Supp. Grp IP Close." 2 "Mean Supp. Grp IP Close." 3 "High Supp. Grp IP Close.")) scheme(s1mono)
*Create a "Figures" subfolder and then save your files
graph save Figures/substance_threat_paper.gph, replace
graph export Figures/substance_threat_paper.pdf, replace

twoway (line intra_lo_IP d_support_mi, sort lcolor(dknavy) lwidth(thick) lpattern(shortdash)) (line intra_mean_IP d_support_mi, sort lcolor(teal) lwidth(thick) lpattern(solid)) (line intra_hi_IP d_support_mi, sort lcolor(lavender) lwidth(thick) lpattern(dash)), ytitle(Intrastate Conflict Escalation Odds Ratio) ytitle(, margin(medium)) ylabel(.5(.5)3.5) xtitle(Change in i's Support Group Military Spending (sd)) xscale(range(0 2)) xlabel(0(.2)2) legend(on order(1 "Low Supp. Grp IP Close." 2 "Mean Supp. Grp IP Close." 3 "High Supp. Grp IP Close.")) scheme(s1mono)
graph save Figures/substance_intra_paper.gph, replace
graph export Figures/substance_intra_paper.pdf, replace


